import static org.junit.Assert.*;

import org.junit.Rule;
import org.junit.Test;
import org.junit.Before;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;

public class CalLogicTest {
	
	CalLogic cal;
	StoreInput input;

	@Before
	public void setUp() {
		cal = new CalLogic();
		input = new StoreInput();
	}

	@Test
	public void testValidDate() {
		boolean thrown = false;
		try {
			cal.validDate("07/31/2014");
		} catch (Exception e){
			thrown = true;
		}
		assertFalse("Valid date has error", thrown);
	}
	
	@Test
	public void testInValidDate() {
		boolean thrown = false;
		try {
			cal.validDate("02/31/2014");
		} catch (Exception e){
			thrown = true;
		}
		assertTrue("Invalid date being processed", thrown);
	}
	
	@Test
	public void testInValidDateFormat() {
		boolean thrown = false;
		try {
			cal.validDate("07-31-2014");
		} catch (Exception e){
			thrown = true;
		}
		assertTrue("Invalid date format", thrown);
	}

	@Test
	public void testValidTime() {
		boolean thrown = false;
		try {
			cal.validTime("11:49 am");
		} catch (Exception e){
			thrown = true;
		}
		assertFalse("Valid time has error", thrown);
	}
	
	@Test
	public void testInValidTime() {
		boolean thrown = false;
		try {
			cal.validTime("13:00 pm");
		} catch (Exception e){
			thrown = true;
		}
		assertTrue("Invalid time being processed", thrown);
	}
	
	@Test
	public void testInValidTimeFormat() {
		boolean thrown = false;
		try {
			cal.validTime("99:99:99");
		} catch (Exception e){
			thrown = true;
		}
		assertTrue("Invalid time format", thrown);
	}
	
	@Test
	public void testConvertDate() {
		try {
			assertEquals("Invalid date conversion", cal.convertDate("8/10/2014"), "20140810");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	/*
	@Test
	public void testCompareDates() {
		try {
			assertEquals("Error when from > to", cal.compareDates("8/10/2014", "8/1/2014"), -1);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		try {
			assertEquals("Error when from == to",cal.compareDates("8/9/2014", "8/10/2014"), 1);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		try {
			assertEquals("Error when from < to", cal.compareDates("8/10/2014", "8/10/2014"), 0);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	@Test
	public void testCompareTimes() {
		try {
			assertEquals("Error when from > to", cal.compareTimes("10:00 pm", "5:00 am"), -1);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		try {
			assertEquals("Error when from == to",cal.compareTimes("10:00 pm", "10:00 pm"), 1);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		try {
			assertEquals("Error when from < to", cal.compareTimes("5:00 am", "10:00 pm"), 0);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	*/
	@Test
	public void testConvertTime() {
		try {
			assertEquals("Invalid time conversion", cal.convertTime("11:00 AM"), "110000");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	@Test
	public void testPrivacy() {
		input.setPrivacy("DEFAULT");//simulate javafx input
		assertTrue("Privacy is not PUBLIC, PRIVACY, or CONFIDENTIAL", 
				input.getPrivacy().equals("PUBLIC") || 
				input.getPrivacy().equals("PRIVACY") || 
				input.getPrivacy().equals("CONFIDENTIAL"));
	}
	
	@Test
	public void testLatitude() {
		input.setLatitude("5464849");//simulate javafx input
		assertTrue("Latitude is not a valid number", 
				(Integer.parseInt(input.getLatitude()) >= -90) && (Integer.parseInt(input.getLatitude()) <= 90));
	}
	
	@Test
	public void testLongitude() {
		input.setLongitude("5464849");//simulate javafx input
		assertTrue("Longitude is not a valid number", 
				(Integer.parseInt(input.getLongitude()) >= -180) && (Integer.parseInt(input.getLongitude()) <= 180));
	}
	
	@Test
	public void testPriority() {
		assertTrue("High priority is not a valid number", 
				(Integer.parseInt(cal.convertPriority("High")) >= 1) && (Integer.parseInt(cal.convertPriority("High")) <= 4));
		assertTrue("Medium priority is not a valid number", 
				Integer.parseInt(cal.convertPriority("Medium")) == 5);
		assertTrue("Low priority is not a valid number", 
				(Integer.parseInt(cal.convertPriority("Low")) >= 6) && (Integer.parseInt(cal.convertPriority("High")) <= 9));

	}
	

}
